// HEAD YieldCurve_QuoteDataFilter H
/*==================================================================================================================
                  Copyright (C) 2013 SUMSCOPE L.P.
                  ALL RIGHTS RESERVED 
====================================================================================================================
File description:
    Filter class to filter original bond quoting price(bid/ask)
====================================================================================================================
...Date      Name                                  Description of Change
13-May-2013  James Xu                              Initial version
14-May-2013  James Xu                              Add GetKeyMaturities and GetFixedPoints
$HISTORY$
===================================================================================================================*/

#ifndef YC_QUOTE_DATA_FILTER_H
#define YC_QUOTE_DATA_FILTER_H

#include "BondDataStructure.h"
#include <vector>
#include "utility.h"

namespace YieldCurve
{
    class QuoteDataFilter
    {
    public:
        QuoteDataFilter(const std::vector<YCInfo>& bondData, const int yieldDate, InterpolatedMethodType InterpolatedMtdType);
        ~QuoteDataFilter(void);

    public:
        virtual std::vector<YieldPoints> GetFilteredPoints();
        
        // Call this method to get adjusted fixed points hourly
        virtual std::vector<YCInfo> GetFixedPoints();


        virtual std::vector<double> GetKeyMaturities();

        static const int QUOTE_SPREADS  = 10; // Filter out quotes if their spreads are over QUOTE_SPREADS bps
        static const int FIXING_SPREADS = 2;  // Adjust fixing points if they deviate from market quotes more than FIXING_SPREADS bps

    private:
        // Remove bid/ofr pairs whose spreads are greater than QUOTE_SPREADS bps.
        virtual void RemoveIneffectiveQuotes();

        // Select best two-side quotes
        // <2013-4-27 James> Currently We will conside best bid/ofr from all source("TPSC", "CFIC", "CBBG",etc.).
        virtual void SelectTwoSideQuotes();

        // Resample fixed points according to the latest curve
        virtual void ResampleFixedPoints();

        // Currently we will simply average fixed quotes from different brokers 
        virtual void CalculateFixedPoints();

        // Adjust fixed points based on the latest quotes
        virtual void AdjustFixedPoints();


    private:
        // Original quote info
        std::vector<YCInfo> bondData_;

        // Interpolated Method Type
        InterpolatedMethodType InterpolatedMtdType_;

        // Quoting date. Format:yyyymmdd, i.e. 20130513
        int yieldDate_;

        // Original best_bid, best_ofr 
        std::vector<double> maturities_;
        std::vector<double> bids_;
        std::vector<double> ofrs_;

        // Effective best_bid, best_ofr.
        std::vector<double> selMaturities_;
        std::vector<double> selBids_;
        std::vector<double> selofrs_;

        // Fixed quotes.
        std::vector<double> fixedMaturities_;
        std::vector<double> fixedQuotes_;
        std::vector<int>    fixedMaturityDate; // format:yyyymmdd

    };
}

#endif